<template>
    <div class="complate">
        <pullRefresh @fetchData="fetchData" v-if="HandoutList" :dataLoaded="dataLoaded" @refresh="refresh" @getScrollTop="getScrollTop" :scrollTop="scroll">
            <div v-for="item in HandoutList" :key="item.EVENT_ID">
                <div class="line-pad"></div>
                <conditionCard :info="item" @click.native="toLink('AdDetails', item.EVENT_ID)" />
            </div>
        </pullRefresh>
        <div v-if="this.$store.state.Administrator.HandoutList === undefined">
            <Alert type="warning">没有需要处理的建议信息。</Alert>
        </div>
    </div>
</template>

<script>
export default {
    components: {
        conditionCard: () => import('@/components/common/conditionCard'),
        pullRefresh: () => import('@/components/common/pullRefresh.vue')
    },
    data() {
        return {
            dataLoaded: false,
            scroll: 0
        }
    },
    computed: {
        HandoutList() {
            try {
                return this.$store.state.Administrator.HandoutList
            } catch (Error) {
                return
            }
        },
    },
    methods: {
        /**
         * 设置已分发列表
         * @pages 页数
         */
        async setHandoutList(pages) {
            const State = this.$store.state
            let HandoutList = await this.$store.dispatch('getHandoutList', {
                userId: State.userInfo.USER_ID,
                page: pages
            })
            if (HandoutList.status === 0) {
                this.$store.commit('SET_HandoutList', HandoutList.result)
            } else {
                this.dataLoaded = true
            }
        },
        /**
         * 设置未分发列表
         * @pages 页数
         */
        async setNotHandoutList(pages) {
            let NotHandoutList = await this.$store.dispatch('getNotHandoutList', {
                page: pages
            })
            if (NotHandoutList.status === 0) {
                this.$store.commit('SET_NotHandoutList', NotHandoutList.result)
            } else {
                this.dataLoaded = true
            }
        },
        fetchData() {
            if (!this.dataLoaded) {
                let tempPage = this.$store.state.Administrator.complatePage
                tempPage++
                this.$store.commit('SET_complatePage', tempPage)
                this.setHandoutList(this.$store.state.Administrator.complatePage)
            }
        },
        refresh() {
            this.$store.commit('SET_HandoutList', null)
            this.dataLoaded = false
            this.$store.commit('SET_complatePage', 1)
            this.setHandoutList(1)
        },
        getScrollTop(scrollTop) {
            this.scroll = scrollTop
        },
        toLink(link, EVENT_ID) {
            sessionStorage.setItem('page', 'complate')
            sessionStorage.setItem('EVENT_ID', EVENT_ID)
            this.$router.push({
                name: link
            })
        }
    },
    created() {
        if (this.$route.params.addIssue) {
            // 如果是从分发页面返回即刷新页面
            this.refresh()
            this.$store.commit('SET_NotHandoutList', null)
            this.setNotHandoutList(1)
        } else {
            this.scroll = this.$store.state.Administrator.complateScroll
        }
    },
    destroyed() {
        this.$store.commit('SET_complateScroll', this.scroll)
    }
}
</script>

<style lang="less">
.complate {
    height: 100%;
    .pullRefresh {
        background-color: #f8f8f8 !important;
    }
}
</style>
